﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace SetTimeTest1
{
    public partial class Form1 : Form
    {
        int timeToSet;
        const int DEFAULT_TIME = 30;// * 1000;

        public Form1()
        {
            InitializeComponent();
            init();
        }

        private void init()
        {
            comboBox1.Items.Add("1/3");
            comboBox1.Items.Add("1/2");
            comboBox1.Items.Add("1");
            comboBox1.Items.Add("2");
            comboBox1.Items.Add("5");
            comboBox1.Items.Add("10");
            comboBox1.Items.Add("20");
            comboBox1.Items.Add("30");
            comboBox1.Items.Add("60");
            comboBox1.Items.Add("90");
            comboBox1.Items.Add("120");
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            String temp = comboBox1.SelectedItem.ToString();
            if (temp.Equals("") || temp == null)
            {
                return;
            } 
            else if (temp.Equals("1/3"))
            {
                timeToSet = 20;// *1000;
            } 
            else if (temp.Equals("1/2"))
            {
                timeToSet = 30;// *1000;
            }
            else
            {
                try
                {
                    timeToSet = Int32.Parse(temp) * 60;// *1000;
                }
                catch (System.FormatException ex)
                {
                    timeToSet = DEFAULT_TIME;
                }
            }
            updateRegistryKey();
        }

        private void updateRegistryKey()
        {
            RegistryKey rk = Registry.LocalMachine.CreateSubKey("PC Asset Geo Tagging\\CellInfo");
            rk.SetValue("ConfigInfo", timeToSet + "", RegistryValueKind.String);
        }
    }
}